import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { rules } from '@pkg/utils';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { categoryList } from '@apps/ant-bus/src/views/business/goods/category/api';
import { weChatList } from '@apps/ant-bus/src/views/business/platformManage/wechat/data/api';
import { payWayList } from '@apps/ant-bus/src/views/business/platformManage/payway/data/api';
import { RenderType } from '@pkg/setting';

export const columns: BasicColumn[] = [
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '用户姓名',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '手机号',
    dataIndex: 'userPhone',
    width: 120,
  },
  {
    title: '商品名称',
    dataIndex: 'goodsName',
    width: 220,
  },
  {
    title: '商品单价',
    dataIndex: 'unitPrice',
    width: 100,
  },
  {
    title: '封面图',
    dataIndex: 'coverImg',
    width: 70,
    customRender: render.renderImage,
  },
  {
    title: '生成数量',
    dataIndex: 'goodsNum',
    width: 100,
  },
  {
    title: '是否支付',
    dataIndex: 'isPay',
    dictData: [
      { label: '未支付', value: 0, color: '#a6a9a6' },
      { label: '已支付', value: 1, color: '#09f137' },
    ],
    width: 120,
    renderType: RenderType.DICT,
  },
  {
    title: '支付方式',
    dataIndex: 'paywayName',
    width: 150,
  },
  {
    title: '所属公众号',
    dataIndex: 'weChatName',
    width: 150,
  },
  {
    title: '操作人',
    dataIndex: 'nickName',
    width: 130,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 220,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'goodsName',
    label: '商品名称',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'nickName',
    label: '操作人',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'weChatId',
    label: '所属公众号',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: weChatList,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '商品',
    field: 'goodsId',
    component: 'ApiModalSelect',
    required: true,
    componentProps: {
      multiple: '',
      selectConfig: {
        api: '/goods/page',
        rowKey: 'goodsId',
        labelKey: 'goodsName',
        modalTitle: '商品选择',
        searchForm: [
          {
            label: '商品分类',
            field: 'categoryId',
            component: 'ApiSelect',
            componentProps: {
              api: categoryList,
              labelField: 'categoryName',
              valueField: 'categoryId',
              immediate: true,
            },
          },
          {
            label: '商品名称',
            field: 'goodsName',
            component: 'Input',
          },
        ],
        columns: [
          {
            title: '商品封面',
            dataIndex: 'coverImg',
            width: 80,
            customRender: render.renderImage,
          },
          {
            title: '商品名称',
            dataIndex: 'goodsName',
            width: 150,
          },
          {
            title: '商品价格',
            dataIndex: 'goodsPrice',
            width: 100,
          },
          {
            title: '会员价格',
            dataIndex: 'vipPrice',
            width: 100,
          },
          {
            title: '创建日期',
            dataIndex: 'createTime',
            width: 150,
          },
        ],
      },
    },
  },
  {
    label: '商品单价',
    field: 'unitPrice',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.price(true),
  },
  {
    label: '商品数量',
    field: 'goodsNum',
    component: 'InputNumber',
    required: true,
    defaultValue: 1,
  },
  {
    label: '用户姓名',
    field: 'userName',
    component: 'Input',
    required: false,
  },
  {
    label: '手机号',
    field: 'userPhone',
    component: 'Input',
    required: true,
    rules: [
      { required: true, message: '请输入手机号' },
      { pattern: /^1[3456789]\d{9}$/, message: '手机号码格式错误！' },
    ],
  },
  {
    label: '是否支付',
    field: 'isPay',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '未支付', value: 0 },
        { label: '已支付', value: 1 },
      ],
    },
  },
  {
    label: '支付类型',
    field: 'payType',
    component: 'Select',
    required: true,
    defaultValue: 'PAY_UNDERLINE',
    componentProps: {
      options: [{ label: '线下支付', value: 'PAY_UNDERLINE' }],
    },
    ifShow: ({ values }) => {
      return values.isPay == 1;
    },
  },
  {
    label: '线下支付',
    field: 'paywayId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: payWayList,
      labelField: 'paywayName',
      valueField: 'paywayId',
      immediate: true,
      showSearch: true,
    },
    ifShow: ({ values }) => {
      return values.isPay == 1;
    },
  },
  {
    label: '所属公众号',
    field: 'weChatId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: weChatList,
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];
